package com.lensong.plugin.sentinel.service;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.lensong.plugin.sentinel.util.DefaultBlockHandlerUtil;
import org.springframework.stereotype.Service;

/**
 * Copyright （c）. All rights reserved.
 *
 * @author len.song
 * @date 2021/09/20
 */
@Service
public class SentinelAnnotationService {


    @SentinelResource(value = "annotationBlockValue01", blockHandler = "doDefaultBlockException", blockHandlerClass = DefaultBlockHandlerUtil.class)
    public String annotationBlock01() {
        System.out.println("SentinelAnnotationTest#annotationBlockValue01 biz is running....");
        return "success";
    }


    @SentinelResource(value = "annotationBlockValue02", blockHandler = "doClassInBlockException")
    public String annotationBlock02() {
        System.out.println("SentinelAnnotationTest#annotationBlockValue02 biz is running....");
        return "success";
    }


    @SentinelResource(value = "annotationFallbackValue01", fallback = "doDefaultFallbackException", fallbackClass = DefaultBlockHandlerUtil.class)
    public String annotationFallbackValue01() {
        System.out.println("SentinelAnnotationTest#annotationFallbackValue01 biz is running....");
        return "success";
    }


    @SentinelResource(value = "annotationFallbackValue02", fallback = "doClassInFallbackException")
    public String annotationFallbackValue02() {
        System.out.println("SentinelAnnotationTest#annotationFallbackValue01 biz is running....");
        return "success";
    }


    public String doClassInBlockException() {
        System.out.println("SentinelAnnotationService#doClassInBlockException inClass blockHandler");
        return "fail";
    }


    public String doClassInFallbackException() {
        System.out.println("SentinelAnnotationService#annotationFallbackValue02 fallback...");
        return "fail";
    }
}
